﻿@using KPIS.GERP.Models.ICM
@model PurchaseRequest

@{
    ViewBag.Title = "แก้ไข รายการขอซื้อ/จ้าง [PR]";
    ViewBag.Descr = "แก้ไข รายการขอซื้อ ขอจ้าง ที่ทางพัสดุทำรายการจากการแจ้งความประสงค์ฯ";
}

@using (Html.BeginForm("Edit", "Purchase", FormMethod.Post, new { @class = "form-horizontal" }))
{
    @Html.AntiForgeryToken()

    <div class="block-button-menu-above">
        @Html.ButtonViewAll()
        @Html.ButtonSubmit()
        @Html.ButtonCancel(Model.PrId)
    </div>
    
    <div class="alert-error">@Html.ValidationSummary()</div>
    @Html.Partial("_EditorForm")
}

@section scripts
{
	<script>
		
		$("form").submit(function (e) {
			e.preventDefault();
			var currentForm = this;
			bootbox.confirm(function (result) {
				if (result) {
					currentForm.submit();
				}
			});
		});
		
		$(function () {
		    ChangeEnableDurType();

		    var PcTypeId = $("#ddlPcTypeId").val();
		    var ddlPcMethodId = $("#ddlPcMethodId");

		    $("#ddlPcTypeId").change(function () {
		        var PcTypeId = $("#ddlPcTypeId").val();
		        var ddlPcMethodId = $("#ddlPcMethodId");

		        ddlPcMethodId.empty();
		        if (PcTypeId != '') {
		            $.getJSON('@Url.Action("GetPurchaseMethod", "Purchase")/' + PcTypeId, function (data) {
		                var items = '';
		                $.each(data, function (i, result) {
		                    ddlPcMethodId.append("<option value='" + result.Value + "'>" + result.Text + "</option>");
		                });
		                ddlPcMethodId.trigger("liszt:updated");//update list
		            });

		            ddlPcMethodId.trigger("liszt:updated");
		        }
		        else {
		        }
		    })
		});
		
		$('input[name=DurTypeId]').change(ChangeEnableDurType);
        
		function ChangeEnableDurType() {
			if ($('#durType2radio').is(':checked')) {
			    $('#RequireDuration').attr('disabled', '');
				$('#DurTypeId').attr('disabled', '');
				$('#DurCountId').attr('disabled', '');
				$('#RequireDate').removeAttr('disabled');
			} else {
				$('#RequireDuration').removeAttr('disabled');
				$('#DurTypeId').removeAttr('disabled');
				$('#DurCountId').removeAttr('disabled');
				$('#RequireDate').attr('disabled', '');
			}
		}

	</script>
}